<%@ page 
import="org.apache.commons.httpclient.*
,org.apache.commons.httpclient.methods.*
,java.net.*
,java.util.ArrayList
,java.util.List
,javax.xml.parsers.SAXParser
,javax.xml.parsers.SAXParserFactory
,org.xml.sax.Attributes
,org.xml.sax.SAXException
,org.xml.sax.helpers.DefaultHandler
,javax.xml.parsers.ParserConfigurationException
,java.io.IOException
,java.io.File
,java.io.FileFilter
,java.util.regex.Pattern
,java.util.regex.Matcher
"%>
<%!

public static String htmlEncode(String s){
    StringBuffer out = new StringBuffer();
    for(int i=0; i<s.length(); i++){
        char c = s.charAt(i);
        if(c > 127 || c=='"' || c=='<' || c=='>'){
           out.append("&#"+(int)c+";");
        }
        else{
            out.append(c);
        }
    }
    return out.toString();
}

%>
<%
String pophost = application.getInitParameter("pophost");
String thedavidport = application.getInitParameter("thedavidport");
String remoteport = application.getInitParameter("remoteport");
String mount=request.getParameter("mount");
String imgsize=request.getParameter("imgsize");
if (imgsize==null){
	imgsize="30";
}



System.out.println("mount="+mount);

// list items in directory
mount=mount.replace("file://","");

String rootpath=mount.replace("smb://POOHBEAR/","/popbox/");
String httppath=mount.replace("smb://POOHBEAR/","/media/");

Pattern coverpattern = Pattern.compile("(cover|folder|front).*(jpg$|jpeg$|png$|gif$)", Pattern.CASE_INSENSITIVE);
File directory = new File(rootpath);
if (directory.isDirectory()){
	//out.print("x");
	for (File thisfile: directory.listFiles()){
	//	out.print("y");
		if (!thisfile.isDirectory()){
		//	out.print("z");
			String name=thisfile.getName();
			Matcher mm=coverpattern.matcher(name);
			if (mm.find()){
				%><img src="<%=httppath+"/"+name %>" height="<%=imgsize%>" width="<%=imgsize%>"/><%
				break;
			}
		}
	}
}
else {
	//out.print("Not Directory path="+rootpath);
}

%>
